Line-based compression for digital image data

ABSTRACT

A method of compressing digital image data is provided that includes selecting an entropy code for encoding a line of pixels in the digital image data, wherein the entropy code is selected from a plurality of variable length entropy codes, using spatial prediction to compute a pixel predictor and a pixel residual for a pixel in the line of pixels, and selectively encoding the pixel residual using one of the entropy code or run mode encoding.

BACKGROUND OF THE INVENTION

The demand for digital video products continues to increase. Someexamples of applications for digital video include video communication,security and surveillance, industrial automation, and entertainment(e.g., DV, HDTV, satellite TV, set-top boxes, Internet video streaming,digital cameras, cellular telephones, video jukeboxes, high-end displaysand personal video recorders). Further, video applications are becomingincreasingly mobile as a result of higher computation power in handsets,advances in battery technology, and high-speed wireless connectivity.

Video compression is an essential enabler for digital video products.Compression-decompression (CODEC) algorithms enable storage andtransmission of digital video. Typically codecs are industry standardssuch as MPEG-2, MPEG-4, H.264/AVC, etc. At the core of all of thesestandards is the hybrid video coding technique of block motioncompensation (prediction) plus transform coding of prediction error.Block motion compensation is used to remove temporal redundancy betweensuccessive pictures (frames or fields) by prediction from priorpictures, whereas transform coding is used to remove spatial redundancywithin each block.

In many digital video products (e.g., a digital still camera, a digitalvideo camera, a cellular telephone), video raw data is captured by asensor and fed into a preview engine for processing. After processing,the resulting video sequence is stored in an external (i.e., off-chip)memory. A video encoder then fetches the video sequence from theexternal memory to encode it. In addition, during encoding, the videoencoder both encodes a picture and stores a decoded copy of the picturein the external memory for use in prediction of a subsequent picture.The video encoder then fetches the decoded copy from the external memorywhen needed to perform prediction. Thus, the video encoder is fetchingboth pictures to be encoded and prior pictures from external memory toperform the encoding, and storing prior pictures in the external memory.

The real-time video data transfer from the preview engine to externalmemory and to and from external memory to the video encoder requires alot of memory bandwidth if the video resolution is D1 (720×480) orhigher. However, memory bandwidth is limited in many digital videoproducts due to both cost and power constraints. Accordingly, reducingmemory bandwidth requirements for processing video data is desirable.

BRIEF DESCRIPTION OF THE DRAWINGS

Particular embodiments in accordance with the invention will now bedescribed, by way of example only, and with reference to theaccompanying drawings:

FIG. 1 shows a block diagram of a digital system in accordance with oneor more embodiments of the invention;

FIG. 2 shows a block diagram of a video encoder in accordance with oneor more embodiments of the invention;

FIG. 3A shows a flow diagram of a method for digital image datacompression in accordance with one or more embodiments of the invention;

FIG. 3B shows a flow diagram of a method for digital image datadecompression in accordance with one or more embodiments of theinvention;

FIG. 4 shows an example of spatial prediction in accordance with one ormore embodiments of the invention;

FIG. 5 shows an example of storage of compressed digital image data inaccordance with one or more embodiments of the invention;

FIGS. 6A, 6B, and 6C show flow diagrams of a method for digital imagedata compression in accordance with one or more embodiments of theinvention;

FIGS. 6D and 6E show a flow diagram of a method for digital image datadecompression in accordance with one or more embodiments of theinvention;

FIG. 7 shows an example of spatial prediction in accordance with one ormore embodiments of the invention;

FIGS. 8-11 show graphs of test results in accordance with one or moreembodiments of the invention; and

FIGS. 12-14 show illustrative digital systems in accordance with one ormore embodiments of the invention.

DETAILED DESCRIPTION OF EMBODIMENTS OF THE INVENTION

Specific embodiments of the invention will now be described in detailwith reference to the accompanying figures. Like elements in the variousfigures are denoted by like reference numerals for consistency.

Certain terms are used throughout the following description and theclaims to refer to particular system components. As one skilled in theart will appreciate, components in digital systems may be referred to bydifferent names and/or may be combined in ways not shown herein withoutdeparting from the described functionality. This document does notintend to distinguish between components that differ in name but notfunction. In the following discussion and in the claims, the terms“including” and “comprising” are used in an open-ended fashion, and thusshould be interpreted to mean “including, but not limited to . . . . ”Also, the term “couple” and derivatives thereof are intended to mean anindirect, direct, optical, and/or wireless electrical connection. Thus,if a first device couples to a second device, that connection may bethrough a direct electrical connection, through an indirect electricalconnection via other devices and connections, through an opticalelectrical connection, and/or through a wireless electrical connection.

In the following detailed description of embodiments of the invention,numerous specific details are set forth in order to provide a morethorough understanding of the invention. However, it will be apparent toone of ordinary skill in the art that the invention may be practicedwithout these specific details. In other instances, well-known featureshave not been described in detail to avoid unnecessarily complicatingthe description. In addition, although method steps may be presented anddescribed herein in a sequential fashion, one or more of the steps shownand described may be omitted, repeated, performed concurrently, and/orperformed in a different order than the order shown in the figuresand/or described herein. Accordingly, embodiments of the inventionshould not be considered limited to the specific ordering of steps shownin the figures and/or described herein. Further, while variousembodiments of the invention are described herein in accordance with theH.264 video coding standard, embodiments for other video codingstandards will be understood by one of ordinary skill in the art.Accordingly, embodiments of the invention should not be consideredlimited to the H.264 video coding standard.

As used herein, the term digital image data refers to pixels in a singledigital image or in a digital video sequence. The pixels may be all or asubset of a single digital image or may be all or a subset of aframe/picture in a digital video sequence, and may be have one ormultiple color components. Further, a line of pixels is a horizontal rowof pixels in a block of digital image data. Accordingly, althoughvarious embodiments of the invention are described herein in referenceto processing of digital video sequences, embodiments for encoding ofdigital still images will be understood by one of ordinary skill in theart.

In general, embodiments of the invention provide for compression anddecompression of digital image data to reduce memory bandwidthrequirements for image/video encoding. More specifically, in one or moreembodiments of the invention, to compress a pixel, spatial prediction isperformed using selected neighboring pixels to compute a pixel predictorand a pixel residual. Then, the pixel is encoded using either variablelength entropy encoding or some other form of encoding. In variousembodiments, the encoding choice is made based on differing codingselection criteria. In some embodiments of the invention, only a singlevariable length code, an exponential Golomb code of order 0, is used forthe entropy encoding and the other form of encoding is N-bit fixedlength coding where N is the number of bits in a pixel.

In some embodiments of the invention, two or more variable length codesare available for entropy coding and a code to be used for the variablelength entropy coding is selected from these codes for each line ofpixels. In such embodiments, the available variable length codes includesome combination of empirically selected Golomb and exponential Golombcodes. Further, the other form of encoding is run mode encoding in whicha consecutive sequence of pixels in a line having zero value residualsis encoded in a single code word. In addition, the coding selectioncriteria used to decide if run mode encoding is to be used is such thatno explicit signal needs to be added to the compressed digital imagedata to signal the decoder to decode the code word using run modedecoding. Instead, the decoder uses the same coding selection criteriato decide if run mode decoding is to be performed.

In one or more embodiments of the invention, to decompress a pixel, thecompression process is essentially reversed. More specifically, spatialprediction is performed using the same selected neighboring pixels thatwere used for encoding the pixel to compute a pixel predictor. Then, thepixel is decoded using either variable length entropy decoding oranother form of decoding corresponding to the other form of encodingused during compression. The decoding choice is made based on the sameselection criteria used to select the encoding during compression.Further, if variable length entropy decoding is selected, the samevariable length code used for encoding is used for decoding.

In some embodiments of the invention, raw digital image data ispre-processed and compressed using a compression method described hereinand stored in an external memory. The compressed data is thendecompressed when fetched from memory by an encoder to be encoded.Further, in some embodiments of the invention, reference data generatedby an encoder during encoding of digital image data is compressed priorto storage in an external memory using a compression method describedherein. The compressed reference data is then decompressed using acorresponding decompression method described herein when fetched fromthe external memory by the encoder for use in encoding.

FIG. 1 shows a block diagram of a digital system in accordance with oneor more embodiments of the invention. The digital system is configuredto perform compression and decompression of digital image data usingembodiments of the methods for compression and decompression describedherein. The digital system (100) includes a video capture component(104), a preview engine (106), a data compression/decompressioncomponent (108), a memory component (110), a video encoder component(114), and a storage component (116). The video capture component (104)is configured to provide digital image data to the preview engine (106).The video capture component (104) may include, for example, an imagesensor such as a charge-coupled device (CCD) or a complementarymetal-oxide-semiconductor (CMOS) sensor that captures analog imageinformation in the form of pixels. The video capture component mayinclude a color separator to separate pixel-sequential image signalsinto color-separated pixel signals, such as primary red (R), green (G)and blue (B) signals. The analog color-separated pixel signals areconverted to digital image signals and provided to the preview engine(106).

The preview engine (106) includes functionality to perform imagepre-processing tasks on the digital input signals. The imagepre-processing tasks enhance the quality of the input image and convertit into a format for further processing, e.g., Y/Cb/Cr 4:2:2 format.These tasks may include color filter array (CFA) interpolation, colorspace conversion, gamma correction, another image enhancement tasks suchas noise filtering and RGB blending. After the pre-processing, thedigital image data is compressed by the data compression/decompressioncomponent (108) and stored in the memory component (110). Thecompression is performed in accordance with an embodiment of a methodfor compression described herein. The memory component (110) may be anysuitable memory technology such as, for example, synchronous dynamicrandom access memory (SDRAM).

The video encoder component (114) includes functionality to encodecaptured, pre-processed digital image data. More specifically, the videoencoder component (114) retrieves the digital image data from the memory(110) via the data compression/decompression component (108) and encodesit for storage in the storage component (116). The datacompression/decompression component (108) decompresses the digital imagedata in accordance with an embodiment of a method for decompression asdescribed herein. The storage component (116) may be any suitablestorage technology, such as, for example, a secure digital card, aninternal hard drive, etc.

In general, the video encoder component (114) retrieves the digitalimage data from the memory (110) as a sequence of video frames, dividesthe frames into coding units which may be a whole frame or a slice of aframe, divides the coding units into blocks of pixels, and encodes thedigital image data in the coding units based on these blocks. During theencoding process, the video encoder component (114) uses reference datafrom previously encoded frames to encode subsequent frames. As isexplained in more detail in reference to FIG. 2, the reference data isgenerated after encoding a frame and is stored, via the datacompression/decompression component (108), in the memory (110). The datacompression/decompression component (108) compresses the reference databefore it is stored in the memory (110) in accordance with an embodimentof a method for compression as described herein. When the reference datais needed, the video encoder component (114) retrieves it from thememory (110) via the data compression/decompression component (108). Thedata compression/decompression component (108) decompresses thereference data prior to providing it to the video encoder component(114) in accordance with an embodiment of a method for decompression asdescribed herein. The functionality of embodiments of the video encodercomponent (114) is described in more detail below in reference to FIG.2.

The video encoder component (114) may perform encoding in accordancewith a video compression standard such as, for example, the MovingPicture Experts Group (MPEG) video compression standards, e.g., MPEG-1,MPEG-2, and MPEG-4, the ITU-T video compressions standards, e.g., H.263and H.264, the Society of Motion Picture and Television Engineers(SMPTE) 421 M video CODEC standard (commonly referred to as “VC-1”), thevideo compression standard defined by the Audio Video Coding StandardWorkgroup of China (commonly referred to as “AVS”), etc. The videoencoder component (114), the preview engine (106), and the datacompression/decompression component (108) may be implemented in anysuitable combination of software, firmware, and hardware, such as, forexample, one or more digital signal processors (DSPs), microprocessors,discrete logic, application specific integrated circuits (ASICs),field-programmable gate arrays (FPGAs), etc.

FIG. 2 shows a block diagram of a video encoder, e.g., the video encoder(114) of FIG. 1, in accordance with one or more embodiments of theinvention. More specifically, FIG. 2 illustrates the basic codingarchitecture of an H.264 encoder. In the video encoder of FIG. 2, inputframes (200) for encoding are provided as one input of a motionestimation component (220), as one input of an intraframe predictioncomponent (224), and to a positive input of a combiner (202) (e.g.,adder or subtractor or the like). In one or more embodiments of theinvention, to reduce memory bandwidth requirements, the input frames(200) may be stored in compressed format in a memory (not shown) anddecompressed prior to being provided to the components of the videoencoder. The compression and decompression of the input frames (200) isperformed in accordance with methods for compression and decompressionas described herein.

The frame storage component (218) provides reference data to the motionestimation component (220) and to the motion compensation component(222). The reference data may include one or more previously encoded anddecoded frames. In some embodiments of the invention, to reduce memorybandwidth requirements, the reference data is compressed by thecompression component (240) prior to storage in the frame storagecomponent (218) and is decompressed by the decompression component (242)prior to being provided to the motion estimation component (220) and themotion compensation component (222). The compression component (240)performs compression in accordance with an embodiment of a method forcompression as described herein and the decompression component (242)performs decompression in accordance with a method for decompression asdescribed herein.

The motion estimation component (220) provides motion estimationinformation to the motion compensation component (222) and the entropyencoders (234). More specifically, the motion estimation component (220)performs tests based on the prediction modes defined in the H.264standard to choose the best motion vector(s)/prediction mode. The motionestimation component (220) provides the selected motion vector (MV) orvectors and the selected prediction mode to the motion compensationcomponent (222) and the selected motion vector (MV) to the entropyencoders (234).

The motion compensation component (222) provides motion compensatedprediction information to a selector switch (226) that includes motioncompensated interframe prediction macroblocks (MBs). The intraframeprediction component (224) also provides intraframe predictioninformation to switch (226) that includes intraframe prediction MBs anda prediction mode. That is, similar to the motion estimation component(220), the intraframe prediction component (224) performs tests based onprediction modes defined in the H.264 standard to choose the bestprediction mode for generating the intraframe prediction MBs.

The switch (226) selects between the motion-compensated interframeprediction MBs from the motion compensation component (222) and theintraframe prediction MBs from the intraprediction component (224) basedon the selected prediction mode. The output of the switch (226) (i.e.,the selected prediction MB) is provided to a negative input of thecombiner (202) and to a delay component (230). The output of the delaycomponent (230) is provided to another combiner (i.e., an adder) (238).The combiner (202) subtracts the selected prediction MB from the currentMB of the current input frame to provide a residual MB to the transformcomponent (204). The resulting residual MB is a set of pixel differencevalues that quantify differences between pixel values of the original MBand the prediction MB. The transform component (204) performs a blocktransform such as DCT, on the residual MB to convert the residual pixelvalues to transform coefficients and outputs the transform coefficients.

The transform coefficients are provided to a quantization component(206) which outputs quantized transform coefficients. Because the DCTtransform redistributes the energy of the residual signal into thefrequency domain, the quantized transform coefficients are taken out oftheir raster-scan ordering and arranged by significance, generallybeginning with the more significant coefficients followed by the lesssignificant by a scan component (208). The ordered quantized transformcoefficients provided via a scan component (208) are coded by theentropy encoder (234), which provides a compressed bitstream (236) fortransmission or storage. The entropy coding performed by the entropyencoder (234) may be any suitable entropy encoding techniques, such as,for example, context adaptive variable length coding (CAVLC), contextadaptive binary arithmetic coding (CABAC), run length coding, etc.

Inside every encoder is an embedded decoder. As any compliant decoder isexpected to reconstruct an image from a compressed bitstream, theembedded decoder provides the same utility to the video encoder.Knowledge of the reconstructed input allows the video encoder totransmit the appropriate residual energy to compose subsequent frames.To determine the reconstructed input, i.e., reference data, the orderedquantized transform coefficients provided via the scan component (208)are returned to their original post-DCT arrangement by an inverse scancomponent (210), the output of which is provided to a dequantizecomponent (212), which outputs estimated transformed information, i.e.,an estimated or reconstructed version of the transform result from thetransform component (204). The estimated transformed information isprovided to the inverse transform component (214), which outputsestimated residual information which represents a reconstructed versionof the residual MB. The reconstructed residual MB is provided to thecombiner (238).

The combiner (238) adds the delayed selected predicted MB to thereconstructed residual MB to generate an unfiltered reconstructed MB,which becomes part of reconstructed frame information. The reconstructedframe information is provided via a buffer (228) to the intraframeprediction component (224) and to a filter component (216). The filtercomponent (216) is a deblocking filter (e.g., per the H.264specification) which filters the reconstructed frame information andprovides filtered reconstructed frames, i.e., reference data orreference frames, to frame storage component (218). In some embodimentsof the invention, the reconstructed frames are compressed by thecompression component (240) in accordance with a compression method asdescribed herein prior to providing them to the frame storage component(218).

FIG. 3A shows a flow diagram of a method for compression of a block ofdigital image data in accordance with one or more embodiments of theinvention. Also, Table 1 below shows a pseudo code example of themethod. The method is explained in reference to FIG. 3A, Table 1, andthe example of FIG. 4. The method is performed in raster scan order onindividual pixels in lines of pixels in the block of digital image dataand may be used in lossless or lossy mode. Further, the method appliedto each color component (e.g., Y, U, V, R, G, B, etc.) independently. Ingeneral, the method performs adaptive sample, i.e., pixel, spatialprediction, quantization, and adaptive fixed-length/variable lengthcoding to compress each pixel.

Initially, the minimum absolute sample difference (MASD) for a pixel tobe compressed is computed based on neighboring reconstructed pixels(300). A reconstructed pixel is a pixel that has been previously encodedusing this method and then reconstructed as described below. In one ormore embodiments of the invention, as shown in the example of FIG. 4,the neighboring reconstructed pixels of a pixel to be encoded, i.e.,pixel X, include the pixel to the immediate left in the same line, i.e.,pixel C, the pixel immediately above in the previous line, i.e., pixelB, and the pixel immediately above and to the left in the previous line,i.e., pixel A. In some embodiments of the invention, if any of theseneighboring reconstructed pixels are not available, then only theavailable neighboring reconstructed pixels are used for computing theMASD. In some embodiments of the invention, if any of these neighboringreconstructed pixels are not available, then a default value, e.g., 128,is used for the unavailable pixels. For example, neighboringreconstructed pixels in the previous line are not available for pixelsin the first line of the digital image data. Similarly, the leftneighboring reconstructed pixel for pixels at the beginning of a line ofdigital image data is not available.

As shown in line 1 of Table 1, to compute the MASD, three absolutesample differences (ASDs) are computed between combinations of thereconstructed neighboring pixels. More specifically, three ASDs arecomputed: the ASD between the top left reconstructed neighbor, i.e.,pixel A, and the top reconstructed neighbor, i.e., pixel B, the ASDbetween the top left reconstructed neighbor, i.e., pixel A, and the leftreconstructed neighbor, i.e., pixel C, and the ASD between the upperleft reconstructed neighbor, i.e., pixel A, and an interpolated pixelvalue computed from the values of the top reconstructed neighbor, i.e.,pixel B, and the left reconstructed neighbor, i.e., pixel C. Theinterpolated pixel value is computed as (B+C+1)/2. The MASD is thenobtained by choosing the minimum value from the three ASDs.

The MASD is then compared to an MASD threshold (302) to decide whetherto use fixed length or variable length coding (VLC). If the MASD isgreater than or equal to the threshold, most likely the prediction errorof the current pixel will also exceed this threshold and there will beno compression gain in encoding the current pixel using the VLC. If theMASD is greater than or equal to an MASD threshold (302), the pixel isencoded using N-bit fixed length lossless coding (306). As shown in line2 of Table 1, in some embodiments of the invention, the MASD thresholdis computed as Q*2^(N−4) where N is the number of bits in the pixel(e.g., 8) and Q is the quantization parameter to be used forquantization if the MASD is not greater than or equal to the MASDthreshold. As shown in line 2 of Table 1, after the lossless coding, thevalue of the reconstructed pixel is set to the value of the pixel. Thecompression then continues with the next pixel in the line if the end ofthe line has not been reached (314) or with the first pixel in the nextline if the end of the block has not been reached (316).

If the MASD is less than the MASD threshold (302), the pixel is encodedusing VLC. To encode the pixel, first a pixel predictor and theprediction error, i.e., pixel residual, is computed (304). As is shownin lines 4-6 of Table 1, the pixel predictor, referred to as Pred in thepseudo code, and the prediction error, referred to as DX in the pseudocode, is computed based on which ASD was selected as the MASD. If theASD of the top left reconstructed neighbor, i.e., pixel A, and the leftreconstructed neighbor, i.e., pixel C, is the MASD, then the predictionerror is the difference between the current pixel i.e., pixel X, and thetop reconstructed neighbor, i.e., pixel B, and the pixel predictor isthe top reconstructed neighbor, i.e., pixel B. If the ASD of the topleft reconstructed neighbor, i.e., pixel A, and the top reconstructedneighbor, i.e., pixel B, is the MASD, then the prediction error is thedifference between the current pixel i.e., pixel X, and the leftreconstructed neighbor, i.e., pixel C, and the pixel predictor is theleft reconstructed neighbor, i.e., pixel C. If the ASD of the top leftreconstructed neighbor, i.e., pixel A, and the interpolated pixel valueis the MASD, then the prediction error is the difference between thecurrent pixel, i.e., pixel X, and the interpolated pixel value and thepixel predictor is the interpolated pixel value.

After the pixel predictor and the prediction error are computed, theprediction error is quantized (308) and encoded using variable lengthcoding (310). In one or more embodiments of the invention, as shown inline 7 of Table 1, the prediction error is quantized using linearquantization based on the quantization parameter used to determine theMASD threshold. The value of sign(DX) is 1 if DX>0; otherwise the valueof sign (XDX)=−1. Also, as shown in line 8, the code used for the VLC isa signed exponential-Golomb (Exp-Golomb) code. Note that if thequantization parameter is 1, the coding is lossless. Otherwise, thecoding is lossy. The signed Exp-Golomb code is shown in a compacted formin Table 2. Symbols x₀, x₁, x₂ . . . can take a value of 0 or 1. Forexample codeword 01x₀ is a compact form for describing two code words:010 corresponding to QDX=+1 and 011 corresponding to QDX=−1. No codetable storage is needed when an Exp-Golomb code is used as the codewords are regularly structured. Other suitable VLC codes may be used inembodiments of the invention.

After encoding, the pixel is reconstructed using the quantized pixelprediction error and the pixel predictor (312). In some embodiments ofthe invention, as shown in line 9 of Table 1, the pixel is reconstructedas the product of the quantized pixel prediction error and thequantization parameter added to the predictor for the pixel. Unless thecurrent pixel is the last pixel in the line, the reconstructed pixelwill be the left reconstructed neighbor for the next pixel in the line.The compression then continues with the next pixel in the line if theend of the line has not been reached (314) or with the first pixel inthe next line if the end of the block has not been reached (316).

TABLE 1  1 MASD = min( abs(A−B), abs(A−C), abs(A − (B+C+1)/2) )  2 If(MASD >=Q*2^(N−4)) { put_bits(stream, N, X); recX = X;}  3 else {  4 if(MASD == abs(A−C)) { DX = X −B; Pred = B;}  5 else if (MASD == abs(A−B)){ DX = X−C; Pred = C;}  6 else { DX = X − (B+C+1)/2; Pred = (B+C+1)/2;} 7 QDX = sign(DX)*( (2*DX + Q) / (2Q));  8 SignedExpGlombCoding(stream,QDX);  9 recX = QDX *Q + Pred; 10 }

TABLE 2 Codeword Code number QDX 1 0 0 01x₀ 1 . . . 2 ±1 001x₁x₀ 3 . . .6 ±2, ±3 0001x₂x₁x₀  7 . . . 14 ±4, ±5, ±6, ±7 . . . k (−1)^(k+1) ×ceil(k ÷ 2) Note: Ceil(x) is the smallest integer greater than or equalto x

FIG. 3B shows a flow diagram of a method for decompression of a block ofdigital image data in accordance with one or more embodiments of theinvention. Also, Table 3 below shows a pseudo code example of themethod. The method is explained in reference to FIG. 3B, Table 3, andthe example of FIG. 4. The decompression method essentially reverses thecompression performed by the compression method of FIG. 3A. Initially,the minimum absolute sample difference (MASD) for a pixel to bedecompressed is computed based on neighboring reconstructed pixels(320). A reconstructed pixel is a pixel that has been previously decodedusing this method and then reconstructed as described below. Theneighboring reconstructed pixels used for computing the MASD are thesame as those used for encoding.

As shown in line 1 of Table 3, the MASD is computed as previouslydescribed. The MASD is then compared to an MASD threshold (322) todecide whether fixed length or variable length coding (VLC) was used toencode the pixel. The MASD threshold is the same as the MASD thresholdused for encoding. If the MASD is greater than or equal to an MASDthreshold (322), the pixel was encoded using N-bit fixed length losslesscoding and is thus decoded using N-bit fixed length decoding (326). Asshown in line 2 of Table 3, after the decoding, the value of thereconstructed pixel is set to the value of the decoded pixel. Thedecompression then continues with the next pixel in the line if the endof the line has not been reached (332) or with the first pixel in thenext line if the end of the block has not been reached (334).

If the MASD is less than the MASD threshold (322), the pixel was encodedusing VLC. To decode the pixel, first a pixel predictor is computed(324). As is shown in lines 4-6 of Table 3, the pixel predictor,referred to as Pred in the pseudo code, is computed based on which ASDwas selected as the MASD. If the ASD of the top left reconstructedneighbor, i.e., pixel A, and the left reconstructed neighbor, i.e.,pixel C, is the MASD, then the pixel predictor is the top reconstructedneighbor, i.e., pixel B. If the ASD of the top left reconstructedneighbor, i.e., pixel A, and the top reconstructed neighbor, i.e., pixelB, is the MASD, then the pixel predictor is the left reconstructedneighbor, i.e., pixel C. If the ASD of the top left reconstructedneighbor, i.e., pixel A, and the interpolated pixel value is the MASD,then the pixel predictor is the interpolated pixel value.

After the pixel predictor is computed, the quantized pixel predictionerror is decoded using the same variable length coding used for encoding(328). In one or more embodiments of the invention, as shown in line 7of Table 3, the code used for the VLC is a signed Exp-Golomb code. Afterdecoding, the pixel is reconstructed using the decoded quantized pixelprediction error and the pixel predictor (312). In some embodiments ofthe invention, as shown in line 9 of Table 1, the pixel is reconstructedas the product of the decoded quantized pixel error and the quantizationparameter used to quantize the pixel prediction error prior to encodingadded to the predictor for the pixel. Unless the current pixel is thelast pixel in the line, the reconstructed pixel will be the leftreconstructed neighbor for the next pixel in the line. The decompressionthen continues with the next pixel in the line if the end of the linehas not been reached (332) or with the first pixel in the next line ifthe end of the block has not been reached (334).

TABLE 3 1 MASD = min( abs(A−B), abs(A−C), abs(A − (B+C+1)/2) ) 2 If(MASD >=Q*2^(N−4)) recX = read_bits(stream, N); 3 else { 4 if (MASD ==abs(A−C)) Pred = B; 5 else if (MASD == abs(A−B)) Pred = C; 6 else Pred =(B+C+1)/2; 7 QDX = SignedExpGlombDecoding(stream); 8 recX = QDX *Q +Pred; 9 }

In one or more embodiments of the invention, to reduce memory bandwidthrequirements, the above method for compression may be used to compressdigital image data for storage in an external memory, i.e., an off-chipmemory, after the frames are captured and some initial image processingis performed to prepare the frames for encoding by a video encoder. Theabove method for decompression is then used to decompress the storedframes prior to processing by the video encoder. Video encoding isgenerally macroblock based. For example, a macroblock may be a 16×16luminance area and corresponding chrominance area of two chrominancecomponents (for chroma format 4:2:0, chrominance area size is 8×8). Ifthe compressed digital image data is stored in memory in the codingorder, i.e., line by line raster scan order, the video encoder may needto first retrieve sufficient compressed data from the external memory todecompress the digital image data for a complete row of macroblocksbefore being able to start actual video compression. Because on-chipmemory is limited in some embedded applications, the video encoder maynot be able to buffer the entire decompressed row of macroblocks inon-chip memory (especially when video resolution is D1 and above), andwould thus have to store the decompressed macroblocks back in theexternal memory. The video encoder would then be required to read thedecompressed macroblocks back from the external memory, thus negatingany memory bandwidth reduction gained by performing the compression.

Accordingly, in some embodiments of the invention, as shown in FIG. 5,the compressed digital image data is stored in the external memory inmacroblock (MB) group order. As shown in FIG. 5, a frame is divided intomacroblock groups that include a number of macroblocks. The size of amacroblock group is determined based on the burst size of the externalmemory and the on-chip memory storage capacity and is selected such thatan entire macroblock group may be stored in the on-chip memory afterdecompression. As is shown in FIG. 5, each MB group is stored in aseparate data buffer in the external memory.

The digital image data is compressed line by line in raster scan order,but each line is divided into sub-lines according to the MB grouppartitioning. The length of each sub-line is exactly the horizontallength of a macroblock group. After each sub-line is compressed, theresulting compressed data is written to the data buffer in the externalmemory corresponding to the MB group to which the sub-line belongs. Theluminance and chrominance components are compressed independently andthe resulting compressed data may be interleaved before storage. Withineach MB group, the compressed data is written into the correspondingdata buffer in external memory in a raster scan order. In one or moreembodiments of the invention, the size of a data buffer is the same asthe size of an uncompressed MB group. In some embodiments of theinvention, the amount of compressed data in each data buffer is madeavailable to the video encoder.

During video encoding, the encoder loads the compressed data MB group byMB group from the external memory based on the amount of compressed datain the corresponding data buffers. That is, the encoder loads thecompressed data for a MB group in the on-chip memory, decompresses thedata, stores the decompressed MB group data in the on-chip memory, andthen encodes the decompressed MB group data. After all the MBs of the MBgroup are encoded, the encoder then loads, decompresses, and encodes thenext group of compressed data. This process is repeated until the entireframe is encoded.

The performance of an embodiment of the above-described compressionmethod was tested in laboratory simulations for both lossy and losslesscompression. For the tests, the first ten frames of four representativeD1 (704×480, progressive scan, 4:2:0) sequences were encoded using thecompression method with Q=3 (lossy) and Q=1 (lossless). For comparisonof the lossy compression, the same sequences were encoded using theH.264 I-frame only encoder (with RD-optimization on and Context AdaptiveVariable Length Coding). The results for Q=3 and the H.264 encoder aresummarized in Table 4 and the results for Q=1 are summarized in Table 5.The compression ratio is the ratio between the original Y, U or Vpicture size and its compressed picture size. The overall compressionratio is the ratio between the total Y, U, V picture size and the totalcompressed picture size.

As shown in Table 4, the compression ratio is highly content dependentand varies from sequence to sequence. At a picture quality ofapproximately 50 dB, the compression method compresses picture data atan overall compression ratio from 1.59 to 3.83, while the H.264 I-frameonly encoder, which is perhaps 1000 times more complex than thecompression method in terms of memory requirements and computationalcomplexity, provides an overall compression ratio from 1.90 to 5.38. Asshown in Table 5, in the lossless case, the compression method providesan overall compression ratio from 1.20 to 2.44.

TABLE 4 Compression Method (Q = 3) H.264 I-frame only (qp = 12) PSNRCompression Overall PSNR Overall (Y, U, V) ratio compression (Y,U,V)compression Sequence [dB] (Y, U, V) ratio [dB] ratio Mobile 49.95,49.84, 1.75, 3.10, 2.06 50.00, 49.68, 2.12 49.87 3.15 49.72 Football49.90, 50.12, 3.28, 4.29, 3.67 49.85, 49.93, 4.49 50.00 5.05 50.47Tennis 50.11, 49.82, 1.21, 4.16, 1.59 50.11, 49.77, 1.90 49.97 4.3149.95 HarryPotter 50.77, 50.30, 3.49, 4.42, 3.83 50.81, 50.46, 5.3850.24 5.19 51.38

TABLE 5 Compression Method (Q = 1) Overall Compression compressionSequence ratio (Y, U, V) ratio Mobile 1.18, 1.90, 1.94 1.36 Football1.92, 2.73, 3.20 2.17 Tennis 0.95, 2.46, 2.57 1.20 HarryPotter 2.22,2.75, 3.46 2.44

FIGS. 6A, 6B, and 6C show flow diagrams of a method for losslesscompression of a block of digital image data in accordance with one ormore embodiments of the invention. In addition, Tables 8 and 10 arepseudo code of portions of the compression method in accordance with oneor more embodiments of the invention. The method is explained inreference to FIGS. 6A, 6B, 6C, the pseudo code of Tables 8 and 10, andthe example of FIG. 7. The method is performed in raster scan order onindividual pixels in lines of pixels in the block of digital image data.Further, the method applied to each color component (e.g., Y, U, V, R,G, B, etc.) independently. In general, as shown in FIG. 6A, the methodperforms adaptive spatial prediction for a pixel, i.e., X, based onneighboring pixels, i.e., A, B, and C, to determine a pixel residual,and then encodes the residual using adaptive variable length coding tocompress the pixel. As is explained in more detail below, if theresidual is 0, the residual may encoded using run mode encoding undercertain conditions. In general, run mode encoding is a technique forencoding a consecutive sequence of zero value pixel residuals in asingle code word. Otherwise, the residual is encoded using regular modeentropy encoding.

As shown in FIG. 6B, at the beginning of each line in the block ofdigital image data, an entropy code is selected for use during regularmode encoding and some initialization is performed for run mode encoding(600). The initialization may include setting a flag, e.g., the runModeflag of Table 8, to indicate that run mode is not currently active. Theentropy code for regular mode encoding is selected based on theprobability distribution of the pixel residuals, i.e., a code with aprobability distribution that best matches the probability distributionof the pixel residual distributions is chosen. In one or moreembodiments of the invention, the entropy code is selected from somenumber of entropy codes that are empirically chosen for a particularembodiment. The number of empirically selected entropy codes availablefor selection depends on the implementation. The selected entropy codeis signaled in the bit stream of compressed digital image data prior tothe compressed digital image data in the line. In other words, when anentropy code is selected for a line, an indicator for the selectedentropy code is included in the compressed digital image data to informa decoder of which entropy code to use for decoding the line.

In one or more embodiments of the invention, the entropy codes providedfor selection include some combination of Golomb codes and exponentialGolomb (exp-Golomb) codes. These particular well-known code types areused at least because they are simple to encode and decode, they havestatic codebooks, i.e., they may be directly calculated so no lookuptable is needed, and the codebooks match well with the pixel residualprobability distributions of a representative sample set of digitalvideo sequences. Further, as is explained in more detail below, thesecodes provide a good compression ratio at fairly low complexity.

Golomb and exp-Golomb codes are entropy codes that are indexed by anon-negative integer value referred to as an “order.” Both code typesinclude non-negative integers as their symbol alphabets. Furthermore,both code types output three part code words that include a unary prefixof zero bits, a binary suffix, and a separator between the prefix andsuffix that is a single 1 bit. Thus, if the prefix of a codeword is qbits long, the separator is a single bit and the suffix is k bits long,the length of the codeword is q+k+1.

To encode a non-negative integer n using a Golomb code of order m, thequotient q and remainder r of n with respect to 2^(m) is calculated asshown in Eq. (1) and Eq. (2), respectively. Note that r corresponds tothe m least-significant bits of the binary representation of n, and qcorresponds to the other, most-significant, bits. The codeword for nconsists of a prefix of q zero bits, the single one bit separator, and asuffix of m bits containing the binary representation of r. Table 6shows Golomb code tables for m=0, m=1, m=2, and m=3. Further, the lengthof the codeword for n is q+1+m.q=n>>m  (1)r=n−q*2^(m)  (2)

TABLE 6 Codeword Range of n m = 0 1 0 0 1 1 0 0 1 2 0 0 0 1 3 . . . . .. m = 1 1 x₀ 0~1 0 1 x₀ 2~3 0 0 1 x₀ 4~5 0 0 0 1 x₀ 6~7 . . . . . . m =2 1 x₁ x₀ 0~3 0 1 x₁ x₀ 4~7 0 0 1 x₁ x₀  8~11 0 0 0 1 x₁ x₀ 12~15 . . .. . . m = 3 1 x₂ x₁ x₀ 0~7 0 1 x₂ x₁ x₀  8~15 0 0 1 x₂ x₁ x₀ 16~23 0 0 01 x₂ x₁ x₀ 24~31 . . . . . .

The exp-Golomb codes are slightly more complex. To encode a non-negativeinteger n using an exp-Golomb code of order k, the number of zero bits qin the prefix of the codeword may be calculated as shown in Eq. (3) andthe value r of the suffix may be calculated as shown in Eq. (4). Thelength of the suffix is q+k. The codeword for n consists of a prefix qzero bits, the single one bit separator, and a suffix of q+k bitscontaining the binary representation of r. The codeword may also beobtained directly as the binary representation of the sum n+2^(k),zero-extended by q bits. Table 7 shows exp-Golomb code tables for k=0,k=1, k=2, and k=3. Further, the length of the codeword for n is 2q+k+1.q=log₂((n+2^(k))>>k)  (3)r=n+2^(k)−2^(n+k)  (4)

TABLE 7 Codeword Range of n k = 0 1 0 0 1 x₀ 1~2 0 0 1 x₁ x₀ 3~6 0 0 0 1x₂ x₁ x₀  7~14 . . . . . . k = 1 1 x₀ 0~1 0 1 x₁ x₀ 2~5 0 0 1 x₂ x₁ x₀ 6~13 0 0 0 1 x₃ x₂ x₁ x₀ 14~29 . . . . . . k = 2 1 x₁ x₀ 0~3 0 1 x₂ x₁x₀  4~11 0 0 1 x₃ x₂ x₁ x₀ 12~27 0 0 0 1 x₄ x₃ x₂ x₁ x₀ 28~59 . . . . .. k = 3 1 x₂ x₁ x₀ 0~7 0 1 x₃ x₂ x₁ x₀  8~23 0 0 1 x₄ x₃ x₂ x₁ x₀ 24~550 0 0 1 x₅ x₄ x₃ x₂ x₁ x₀  56~119 . . . . . .

Referring again to FIG. 6B, in one or more embodiments of the invention,the entropy code to be used for regular mode encoding is selected byperforming enough of the encoding process on the line of pixels usingeach of the provided entropy codes for regular mode encoding todetermine which of the entropy codes produce the best compression. Morespecifically, a residual is computed for each pixel and then eitherregular mode encoding or run mode encoding of the residual is selectedas described in more detail below. If run mode encoding is selected,sufficient processing is performed to move the process to the next pixelin the line without encoding the residual. If regular mode encoding isselected, the length of the codeword for the pixel residual is computedfor each entropy code and added to a bit count for each entropy code.After all pixels in the line are processed, the entropy code thatgenerated the smallest bit count is selected for use in regular modeencoding. This approach for selecting the entropy code is referred toherein as the two-pass approach.

In some embodiments of the invention, the entropy code to be used forregular mode encoding is selected as the entropy code that would haveproduced the best compression for the previous line of pixels. Morespecifically, as the previous line of pixels is encoded, when regularmode encoding is selected for a pixel residual, the length of thecodeword for the pixel residual is computed for each available entropycode and added to a bit count for the entropy code. The entropy codewith the smallest bit count is then selected for use in regular modeencoding of the next line of pixels. In these latter embodiments, if aline of pixels is the first line of pixels in the digital image data,the entropy code used for regular mode encoding may be a default entropycode, may be selected by encoding the line of pixels using each of theentropy codes as previously described, etc. This approach for selectingthe entropy code is referred to herein as the one-pass approach.

Once the initialization is performed and the entropy code is selected(600), each of the pixels in the line is encoded. First, a pixelpredictor and a pixel residual, i.e., prediction error, are computed fora pixel (602) using spatial prediction. The computation of the pixelpredictor and pixel residual is similar to that described above inrelation to FIG. 3A. First, the minimum absolute sample difference(MASD) for the pixel is computed based on neighboring pixels. In one ormore embodiments of the invention, as shown in the example of FIG. 7,the neighboring pixels of a pixel to be encoded, i.e., pixel X, includethe pixel to the immediate left in the same line, i.e., pixel C, thepixel immediately above in the previous line, i.e., pixel B, and thepixel immediately above and to the left in the previous line, i.e.,pixel A. In some embodiments of the invention, if any of theseneighboring pixels are not available, then only the availableneighboring pixels are used for computing the MASD. In some embodimentsof the invention, if any of these neighboring pixels are not available,then a default value, e.g., 128, is used for the unavailable pixels.

To compute the MASD, three absolute sample differences (ASDs) arecomputed between combinations of the neighboring pixels. Morespecifically, three ASDs are computed: the ASD between the top leftneighbor, i.e., pixel A, and the top neighbor, i.e., pixel B, the ASDbetween the top left neighbor, i.e., pixel A, and the left neighbor,i.e., pixel C, and the ASD between the top left neighbor, i.e., pixel A,and an interpolated pixel value computed from the values of the topneighbor, i.e., pixel B, and the left neighbor, i.e., pixel C. Theinterpolated pixel value is computed as (B+C)/2. The MASD is thenobtained by choosing the minimum value from the three ASDs.

The pixel predictor and the pixel residual are then computed based onwhich ASD was selected as the MASD. If the ASD of the top left neighbor,i.e., pixel A, and the left neighbor, i.e., pixel C, is the MASD, thenthe pixel residual is the difference between the current pixel i.e.,pixel X, and the top neighbor, i.e., pixel B, and the pixel predictor isthe top neighbor, i.e., pixel B. If the ASD of the top left neighbor,i.e., pixel A, and the top neighbor, i.e., pixel B, is the MASD, thenthe pixel residual is the difference between the current pixel i.e.,pixel X, and the left neighbor, i.e., pixel C, and the pixel predictoris the left neighbor, i.e., pixel C. If the ASD of the top leftneighbor, i.e., pixel A, and the interpolated pixel value is the MASD,then the prediction error is the difference between the current pixel,i.e., pixel X, and the interpolated pixel value and the pixel predictoris the interpolated pixel value.

Once the pixel predictor and pixel residual are computed (602), a checkis made to determine if run mode is currently active or if run mode isnot currently active, whether or not run mode should be entered (604).If run mode is currently active, then run mode encoding is performed forthe pixel (608). As shown in line 17 of Table 8, determining if run modeis active may include checking a flag, e.g., runMode. If run mode is notcurrently active, then a check is made to determine if run mode shouldbe activated for the pixel. In one or more embodiments of the invention,if the pixel residual of the previous pixel, i.e., the left neighbor(pixel C in FIG. 7), is 0 and selected neighboring pixels have the samevalue, run mode is activated.

In some embodiments of the invention, the neighboring pixels consideredare the top left neighbor, i.e., pixel A, the top neighbor, i.e., pixelB, the top right neighbor, i.e., pixel D, and the left neighbor, i.e.,pixel C. In some embodiments, if the pixel residual of C is 0 andA=B=C=D, then run mode is activated. Alternatively, in some embodiments,run mode is activated if the pixel residual of C is 0 and A=C.Alternatively, in some embodiments, run mode is activated if the pixelresidual of C is 0 and A=B=D. Lines 9 and 10 of Table 8 are an exampleof determining whether or not run mode is to be activated. In someembodiments of the invention, if a neighbor is not available, the valueis assumed to be 128. In some embodiments of the invention, if aneighbor is not available, the value may be assumed to be any reasonablevalue or may be ignored for purposed of the determination. If run modeis to activated, then an indicator that run mode is active is set, e.g.,the runMode flag of Table 8, and some initialization for run modeencoding is performed. As shown in lines 12-14 of Table 8, thisinitialization may include setting the initial code length (codeLength)for coding a run of zero residual values to two, and setting the countof the number of zero residual values encoded (zeroRunLength) to 0. Theuse of the code length and the count of zero residual values areexplained in more detail below in reference to FIG. 6C.

If run mode is active or activated (604), the pixel is encoded byperforming run mode encoding (608). In run mode encoding, runs, i.e.,consecutive sequences of zero value pixels residuals are encoded in asingle codeword. FIG. 6C shows a flow diagram of a method for run modeencoding in accordance with one or more embodiments of the invention. Ifthe pixel residual of the current pixel is 0 (624), then the count ofthe number of consecutive pixel residuals having a value of zero isincremented (626). If this count is equal to the current code length(628), then a zero value bit is output (630) as the encoding of aconsecutive sequence of zero value residuals of length code length. Forexample, if the code length is two, the zero value bit represent a runof two consecutive zero value residuals. In addition, the code length isdoubled and the zero count is reset to 0 (630). The encoding thencontinues with the next step in FIG. 6B. If the count of the number ofconsecutive zero value pixel residuals is not equal to the code length(628), then the encoding continues with the next step in FIG. 6B.

If the pixel residual of the current pixel is not zero (624), then runmode encoding is terminated and the pixel residual will be encoded usingregular mode encoding. First a bit with a value of one is output toindicate the end of a run (632). Then, the current count of the numberof consecutive zero value pixel residuals is output as a binary numberof length of log₂(code length), and run mode encoding is ended (632). Inone or more embodiments of the invention, ending run mode includessetting an indicator that run mode is not active, e.g., the runMode flagof Table 8. After run mode encoding is terminated, encoding continueswith the next step in FIG. 6B.

The result of run mode encoding is that a consecutive sequence of zerovalue pixel residuals in a line of pixels is encoded as a code word withunary prefix having some number of zero value bits, a binary suffix, anda separator between the prefix and suffix that is a single 1 bit. Eachzero value bit in the prefix represents a subset, i.e., run, of theconsecutive sequence of zero value pixel residuals where the size of thesubset is a power of two. More specifically, the first zero value bit inthe prefix represents the first two zero value pixel residuals in thesequence, the second zero value bit in the prefix represents the nextfour zero value pixel residuals in the sequence, etc. The separator,i.e., the one bit, signals that the sequence is ending, i.e., that anon-zero pixel residual is coming up following the suffix. The suffix isa binary number indicating how many additional zero value pixelresiduals are in the sequence prior to the non-zero pixel residual. Thatis, the suffix encodes the remaining zero value pixels in the sequence.The length of the suffix, i.e., the number of bits in the suffix, islog₂(L) where L is the length of the subset that was being encoded whenthe non-zero pixel residual was encountered.

Said another way, the code word has a unary prefix of N zero value bitsrepresenting N consecutive subsets, i.e., runs, of the consecutivesequence of zero value pixel residuals, a binary suffix of lengthlog₂(N+1) bits, and a single one value bit between the unary prefix andthe binary suffix. Each bit position n=1 to N in the unary prefixencodes an nth subset of length 2^(n) of the N consecutive subsets. Thebinary suffix is a binary number indicating a number M of zero valuepixel residuals in the (N+1)th consecutive subset of the consecutivesequence, wherein M<N+1.

For example, if the sequence of pixel residuals is 00,0000,000002, theresulting code word will be 001101. In this code word, the prefix is 00and the suffix is 101. The first 0 bit in the prefix represents thefirst two zero value pixel residuals in the sequence, the second 0 bitin the prefix represents the next four zero value pixel residuals in thesequence, the first 1 bit is the separator that signals that the nexteight residuals are not all zeros, and the next three bits, i.e., thesuffix 101, and indicate that there five leading zeros in the next eightresiduals. The nonzero pixel residual 2 in this example will be encodedwith regular mode encoding.

Table 8 is pseudo code of a method for run mode encoding in accordancewith one or more embodiments of the invention. The pseudo code isexpressed using the C programming language and will be understood by oneof ordinary skill in the art based on the above description of FIG. 6Cand the comments in the pseudo code.

TABLE 8  1 // set runMode flag at the beginning of each line  2 //prevResidual −> residual of previous pixel  3 // pixelIdx => pixel index 4 // width => number of pixels in a line  5 residual =SpatialPrediction(A, B, C, D, X);  6 // check if coding enters the zerorun coding mode  7 // note once enters the zero run coding, this checkis no longer performed  8 // zero run coding mode exits when the nextresidual is non-zero  9 if (runMode == 0 && pixelIdx > 0 && prevResidual== 0 && (A == B) 10 && (A == C) && (A == D)) { 11 runMode = 1; // turnon zero run coding flag 12 codeLength = 2; // set the initial codelength 13 g = 1; // g = log2(L) 14 zeroRunLength = 0; // set zero runlength to zero 15 } 16 /****** Zero run mode coding ******/ 17 if(runMode) { 18 /**** coding for the residual = 0 case ****/ 19 if(residual == 0) { 20 zeroRunLength++; // add the zero run length by one21 if (zeroRunLength == codeLength) { 22 // if zero run length equalscodeLength, insert one-bit 0 into bit stream 23 // and double the length24 put_bits(stream, 1, 0); 25 zeroRunLength = 0; 26 codeLength <<= 1; 27g++; 28 } else if (pixelIdx == width − 1) { // force exit because of endof line 29 // if the current pixel is the last pixel of the line 30 //insert one-bit zero into the bit stream and exit 31 put_bits(stream, 1,0); 32 } 33 } else { 34 /**** coding for residual != 0 case, ends runmode encoding ***/ 35 put_bits(stream, 1, 1); // put one-bit one in bitstream to indicate end of run mode 36 put_bits(stream, g,zeroRunLength); // encoding the remaining value of zero run 37 mapmode =2; // set mapping mode to 2 for the 1st residual after run mode 38 //note that the 1st residual after zero run coding will never be zero 39runMode = 0; // turn off the run mode encoding 40 } 41 }

Referring again to FIG. 6B, after run mode encoding is performed (608),a check is made to determine if run mode encoding was deactivated (609).As previously mentioned, run mode encoding is ended if the value of thecurrent pixel residual is not zero. If run mode encoding was notdeactivated (609), the encoding continues with the next pixel in theline (610) or with the first pixel in the next line (612) unless the endof the block has been reached.

If run mode encoding was deactivated (609), or if run mode was notactive or activated (604), the pixel residual is encoded using theselected entropy code. First, the signed pixel residual is mapped tounsigned code number using a suitable mapping function. In one or moreembodiments of the invention, the mapping is performed in accordancewith Table 9. After mapping, the code number is encoded using theselected entropy code. After the pixel residual is encoded using theselected entropy code (606), the encoding continues with the next pixelin the line (610) or with the first pixel in the next line (612) unlessthe end of the block has been reached.

TABLE 9 Code Number Residual 0 0 1 1 2 −1 3 2 4 −2 5 3 6 −3 r (−1)^(r+1)× Ceil(r ÷ 2)

Table 10 is pseudo code of a method for regular mode encoding of a pixelresidual in accordance with one or more embodiments of the invention.The pseudo code is expressed using the C programming language and willbe understood by one of ordinary skill in the art based on the abovedescription of FIG. 6B and the comments in the pseudo code. The methodof Table 10 assumes that the previously described one-pass approach forselecting the entropy code is used. In the pseudo code, ks is thecurrently selected entropy code, KMAX is the maximum order of theExp-Golomb codes from which a code selection may be made, and MMAX isthe maximum order of the Golomb codes from a code selection may be made.Further, in the pseudo code, an optimization is used to take advantageof the fact that the first pixel residual after the end of run modecoding will always be non-zero. For this optimization, the code table ofTable 9 is shifted up by 1, i.e., code number 0 corresponds to a pixelresidual=1, code number 1 corresponds to a pixel residual=−1, etc. Theflag mapmode is used to control use of the optimization.

TABLE 10  1 Void RegularEntropyCoding (  2 Bitstream * stream, // bitstream pointer  3 S16 residual, // pixel residual after spatialpredication  4 S16 ks, // selected index: 0 ~ KMAX−1 Exp-Golomb codes, 5 // KMAX ~ KMAX+MMAX −1 => Golomb codes  6 S08 mapmode, // mappingresidual to codeNum mode 1 or 2  7 // for the first non-zero residualafter the zero run coding  8 // mapmode = 2 because this residual isalways non-zero  9 S32 * bitsNum) // array to accumulate number of bitsused by different codes 10 { 11 S16 n, but, CodeNum, k; 12 S16 m, q; 13U16 infoCode; // suffix of a code word 14 // map the residual tounsigned coding number 15 CodeNum = 2 * abs(residual) − mapmode; 16 if(residual >= 0) CodeNum++; 17 // loop through the KMAX Exp-Golomb codesto count number of bits 18 // encode the residual if the selected codeks is one of Exp-Golomb codes 19 for(k = 0; k < KMAX; k++) { 20 //compute used number of bits 21 buf = (CodeNum + (1<<k) )>> k; 22 n =numberofLeadZeroBits(buf); 23 bitsNum[k] += (2 * n + 1 + k); 24 //encoding for selected Exp-Golomb code 25 if (k == ks) { 26 infoCode =CodeNum + (1<<k) − (1 << (n + k)); 27 put_bits(stream, n+1, 1); 28 if(n + k) 29 put_bits(stream, n + k, infoCode); 30 } 31 } 32 // loopthrough the MMAX Golomb codes to count number of bits 33 // encode theresidual if the selected code ks is one of Golomb codes 34 for (m = 0; m< MMAX; m++) { 35 // compute used number of bits 36 q = CodeNum >> m; 37bitsNum[m + KMAX] += q + 1 + m; 38 // encoding for selected Golomb code39 if (m == ks − KMAX) { 40 infoCode = CodeNum − q * (1 << m); 41put_bits(stream, (q + 1), 1); 42 if (m) put_bits(stream, m, infoCode);43 } 44  } 45 }

FIGS. 6D and 6E show flow diagrams of a method for decompression ofdigital image data compressed using the method for lossless compressionof FIGS. 6A-6C in accordance with one or more embodiments of theinvention. At the beginning of each line in the digital image data, anentropy code is selected for use during regular mode decoding (640).That is, an indicator of which entropy code to use is read from the bitstream of compressed digital video data. Once the entropy code isselected (640), each of the pixels in the line is decoded. First, apixel predictor is computed for the current pixel to be decoded (642)using spatial prediction. The computation of the pixel predictor issimilar to that described above in relation to FIG. 6B. First, theminimum absolute sample difference (MASD) for the pixel is computedbased on neighboring decoded pixels. The neighboring pixels used forcomputing the MASD are the same as those used for computing the MASDduring encoding and the MASD is computed as previously described inrelation to FIG. 6B.

The pixel predictor is then computed based on which ASD was selected asthe MASD. If the ASD of the top left neighbor, i.e., pixel A, and theleft neighbor, i.e., pixel C, is the MASD, then the pixel predictor isthe top neighbor, i.e., pixel B. If the ASD of the top left neighbor,i.e., pixel A, and the top neighbor, i.e., pixel B, is the MASD, thenthe pixel predictor is the left neighbor, i.e., pixel C. If the ASD ofthe top left neighbor, i.e., pixel A, and the interpolated pixel valueis the MASD, then the pixel predictor is the interpolated pixel value.

Once the pixel predictor is computed (642), a check is made to determineif run mode decoding is to be performed (644). The same criteria thatwas used during encoding to decide whether or not to activate run modeencoding is used to determine if run mode decoding is to be performed.In one or more embodiments of the invention, when the pixel residual ofthe previous pixel, i.e., the left neighbor (pixel C in FIG. 7), is 0and selected neighboring decoded pixels have the same value, run modedecoding is performed. In some embodiments of the invention, theneighboring pixels considered are the top left neighbor, i.e., pixel A,the top neighbor, i.e., pixel B, the top right neighbor, i.e., pixel D,and the left neighbor, i.e., pixel C. In some embodiments, if the pixelresidual of C is 0 and A=B=C=D, then run mode decoding is performed.Alternatively, in some embodiments, run mode decoding is performed ifthe pixel residual of C is 0 and A=C. Alternatively, in someembodiments, run mode decoding is performed if the pixel residual of Cis 0 and A=B=D. If run mode decoding is to be performed, someinitialization for run mode decoding may be performed such as settingthe initial code length to two, and setting the count of the number ofzero residual values decoded to 0. The code length indicates the lengthof a run of zero residual values, i.e., how many pixel residuals areincluded in a run, and the count of the number of zero residual valuesindicates how many pixels in the run have been decoded.

If run mode decoding is to be performed (644), then some number ofconsecutive pixels that were encoded using run mode encoding are decodedusing run mode decoding. As was previously explained, a consecutivesequence of pixels having zero residual values may be encoded in runmode as a codeword having a prefix, a separator, and a suffix. Theprefix of the code word is a sequence of binary zeros in which eachbinary 0 represents a run of consecutive zero residual values, theseparator is a binary 1, and the suffix is a binary number indicatingthe remaining number of zero residual values encoded by the code word.In general, run mode decoding reverses the run mode encoding.

FIG. 6E shows a flow diagram of a method for run mode decoding inaccordance with one or more embodiments of the invention. If the nextbit is a 0 bit (660), then a run of pixels of length code length is tobe decoded. The count of the number of zero residual values isincremented (664) and the current pixel is reconstructed based on thecurrent pixel predictor (666). More specifically, the decoded valueoutput for the current pixel is that of the predictor computed for thepixel. After the current pixel is reconstructed, a pixel predictor iscomputed for the next pixel (668). Then, a check is made to determine ifall pixels in the run have been decoded, i.e., if the count of thenumber of zero residual values is equal to the code length (670). If allof the pixels in the run have not been decoded, decoding of the runcontinues (664). If all of the pixels in the run have been decoded, thenthe code length is doubled, the count of the number of pixel residualsis reset to zero (672), and the next bit is read (660).

If the next bit is a 1 bit (i.e., the separator) (660), then run modedecoding is to be terminated. The suffix of the code word is read todetermine the count of the remaining number of pixels to be decoded andthis count is assigned as the code length (674). As was previouslyexplained, the suffix is a binary number of length log₂(code length). Ifthis count is 0 (676), the run mode decoding is ended. Otherwise, anumber of pixels equal to the count are decoded. A process ofincrementing the count of zero value residuals decoded (678),reconstructing the pixel (680), and computing the pixel predictor forthe next pixel (684) is repeated until the remainder of the pixelsencoded by the code word are decoded (682).

Referring again to FIG. 6D, after run mode decoding is performed (648),the decoding continues with the next pixel in the line (652) or thefirst pixel in the next line (654) unless the end of the block has beenreached.

If run mode decoding is not to be performed (644), the pixel residualfor the current pixel is decoded using the selected entropy code (646).The current pixel is then reconstructed based on the pixel predictor andthe pixel residual (650), i.e., the decoded value of the current pixelis the sum of the predictor and the residual. Decoding then continueswith the next pixel in the line (652) or the first pixel in the nextline (654) unless the end of the block has been reached.

The performance of embodiments of the above-described compression methodwere tested in laboratory simulations using various combinations ofGolomb and exp-Golomb codes and the one-pass and two-pass approaches forselecting the entropy code for a line. FIGS. 8-11 show graphs of thetest results. For each of the tests, eighteen representative HD 1080p4:2:0 video sequences were compressed. Further, for these tests,reconstructed reference data generated by H.264 encoding of the eighteenHD sequences with four different quantization parameters (QP), 22, 27,32, and 37 was also used. In each of the graphs, the data labeled “orig”represents results from applying the compression on original videosequences.

FIG. 8 is a graph of test results in which the bits per pixel (bpp) lossincurred using the one-pass approach for selecting the entropy code iscompared to using the two-pass approach. For this graph, the bpp losspercentage is the percentage decrease in the number of bits used forencoding when the two-pass approach is used as compared to using theone-pass approach. For these tests, six entropy codes were available forselection for both the one pass approach and the two-pass approach,three Golomb codes of order m=0, 1, and 2 and three exp-Golomb codes oforder k=0, 1, and 2. As can be seen from this graph, the two-passapproach required fewer bits than the one-pass approach, but thedifference is not significant.

FIG. 9 is a graph of test results in which the bits per pixel (bpp) lossincurred using the one-pass approach for selecting the entropy code withfour different combinations of two entropy codes available for selectionis compared to using the two-pass approach with six entropy codesavailable for selection. For this graph, the bpp loss percentage is thepercentage decrease in the number of bits used for encoding when thetwo-pass approach is used as compared to using the one-pass approachwith each of the four combinations of two entropy codes. For all of thetests, the six entropy codes available for selection for the two-passapproach were three Golomb codes of order m=0, 1, and 2 and threeexp-Golomb codes of order k=0, 1, and 2. The four combinations ofentropy codes available for selection for the one-pass approach were: 1)the exp-Golomb code of order k=0 and the Golomb code of order m=1; 2)the exp-Golomb code of order k=0 and the Golomb code of order m=2; 3)the exp-Golomb code of order k=1 and the Golomb code of order m=1; and4) the Golomb codes of order m=1 and 2.

FIG. 10 is a graph of test results in which the bits per pixel (bpp)loss incurred using the one-pass approach for selecting the entropy codewith four different combinations of four entropy codes available forselection is compared to using the two-pass approach with six entropycodes available for selection. For this graph, the bpp loss percentageis the percentage decrease in the number of bits used for encoding whenthe two-pass approach is used as compared to using the one-pass approachwith each of the four combinations of four entropy codes. For all of thetests, the six entropy codes available for selection for the two-passapproach were three Golomb codes of order m=0, 1, and 2 and threeexp-Golomb codes of order k=0, 1, and 2. The four combinations ofentropy codes available for selection for the one-pass approach were: 1)the exp-Golomb codes of order k=0, 1, 2, and 3; 2) the exp-Golomb codesof order k=0, 1, and 2 and the Golomb code of order m=1; 3) theexp-Golomb codes of order k=0, 1, and 2 and the Golomb code of orderm=2; and 4) the exp-Golomb codes of order k=0 and 1 and the Golomb codesof order m=1 and 2. As can be seen from this graph, the percentagedifference in bit count between the two pass approach using six entropycodes and the one pass approach using the exp-Golomb codes of order k=0and 1 and the Golomb codes of order m=1 and 2 was very insignificant.

FIG. 11 is a graph of the detailed test results in which the bits perpixel (bpp) loss incurred using the one-pass approach for selecting theentropy code with the Golomb codes of order k=0 and 1 and the exp-Golombcodes of order m=1 and 2 available for selection is compared to usingthe two-pass approach with six entropy codes as previously describedavailable for selection. For this graph, the bpp loss percentage is thepercentage decrease in the number of bits used for encoding when thetwo-pass approach with six entropy codes is used as compared to usingthe one-pass approach with the four specific entropy codes.

Based on these test results, embodiments of the invention using theone-pass approach for entropy code selection in conjunction with twoexp-Golomb codes of order k=0 and 1 and two Golomb codes of order m=1and 2 provide results that are comparable to using a more complexapproach of using the two-pass approach for entropy code selection inconjunction with six entropy codes. Further, if less complexity isdesired, embodiments of the invention using the one-pass approach forentropy selection with two codes, a Golomb code of order m=1 and anexp-Golomb code of order k=0 provide acceptable results.

Embodiments of the encoders and methods described herein may be providedon any of several types of digital systems: digital signal processors(DSPs), general purpose programmable processors, application specificcircuits, or systems on a chip (SoC) such as combinations of a DSP and areduced instruction set (RISC) processor together with variousspecialized programmable accelerators. A stored program in an onboard orexternal (flash EEP) ROM or FRAM may be used to implement the videosignal processing. Analog-to-digital converters and digital-to-analogconverters provide coupling to the real world, modulators anddemodulators (plus antennas for air interfaces) can provide coupling fortransmission waveforms, and packetizers can provide formats fortransmission over networks such as the Internet.

The techniques described in this disclosure may be implemented inhardware, software, firmware, or any combination thereof. If implementedin software, the software may be executed in one or more processors,such as a microprocessor, application specific integrated circuit(ASIC), field programmable gate array (FPGA), or digital signalprocessor (DSP). The software that executes the techniques may beinitially stored in a computer-readable medium such as compact disc(CD), a diskette, a tape, a file, memory, or any other computer readablestorage device and loaded and executed in the processor. In some cases,the software may also be sold in a computer program product, whichincludes the computer-readable medium and packaging materials for thecomputer-readable medium. In some cases, the software instructions maybe distributed via removable computer readable media (e.g., floppy disk,optical disk, flash memory, USB key), via a transmission path fromcomputer readable media on another digital system, etc.

Embodiments of the methods for digital image compression anddecompression as described herein may be implemented for virtually anytype of digital system (e.g., a desk top computer, a laptop computer, ahandheld device such as a mobile (i.e., cellular) phone, a personaldigital assistant, a digital camera, etc.) with functionality to captureor otherwise generate digital image data. FIGS. 12-14 show blockdiagrams of illustrative digital systems.

FIG. 12 shows a digital system suitable for an embedded system (e.g., adigital camera) in accordance with one or more embodiments of theinvention that includes, among other components, a DSP-based imagecoprocessor (ICP) (1202), a RISC processor (1204), and a videoprocessing engine (VPE) (1206) that may be configured to perform methodsfor digital image data compression and decompression described herein.The RISC processor (1204) may be any suitably configured RISC processor.The VPE (1206) includes a configurable video processing front-end (VideoFE) (1208) input interface used for video capture from imagingperipherals such as image sensors, video decoders, etc., a configurablevideo processing back-end (Video BE) (1210) output interface used fordisplay devices such as SDTV displays, digital LCD panels, HDTV videoencoders, etc, and memory interface (1224) shared by the Video FE (1208)and the Video BE (1210). The digital system also includes peripheralinterfaces (1212) for various peripherals that may include a multi-mediacard, an audio serial port, a Universal Serial Bus (USB) controller, aserial port interface, etc.

The Video FE (1208) includes an image signal processor (ISP) (1216), anda 3A statistic generator (3A) (1218). The ISP (1216) provides aninterface to image sensors and digital video sources. More specifically,the ISP (1216) may accept raw image/video data from a sensor (CMOS orCCD) and can accept YUV video data in numerous formats. The ISP (1216)also includes a parameterized image processing module with functionalityto generate image data in a color format (e.g., RGB) from raw CCD/CMOSdata. The ISP (1216) is customizable for each sensor type and supportsvideo frame rates for preview displays of captured digital images andfor video recording modes. The ISP (1216) also includes, among otherfunctionality, an image resizer, statistics collection functionality,and a boundary signal calculator. The 3A module (1218) includesfunctionality to support control loops for auto focus, auto whitebalance, and auto exposure by collecting metrics on the raw image datafrom the ISP (1216) or external memory.

The Video BE (1210) includes an on-screen display engine (OSD) (1220)and a video analog encoder (VAC) (1222). The OSD engine (1220) includesfunctionality to manage display data in various formats for severaldifferent types of hardware display windows and it also handlesgathering and blending of video data and display/bitmap data into asingle display window before providing the data to the VAC (1222) inYCbCr format. The VAC (1222) includes functionality to take the displayframe from the OSD engine (1220) and format it into the desired outputformat and output signals required to interface to display devices. TheVAC (1222) may interface to composite NTSC/PAL video devices, S-Videodevices, digital LCD devices, high-definition video encoders, DVI/HDMIdevices, etc.

The memory interface (1224) functions as the primary source and sink tomodules in the Video FE (1208) and the Video BE (1210) that arerequesting and/or transferring data to/from external memory. The memoryinterface (1224) includes read and write buffers and arbitration logic.In one or more embodiments of the invention, the Video FE (1208) and theVideo BE (1210) are configured to perform compression of digital imagedata prior to transferring the data to external memory in accordancewith a compression method described herein and to perform decompressionof digital image data when transferring the data from external memory.

The ICP (1202) includes functionality to perform the computationaloperations required for video encoding other processing of capturedimages. The video encoding standards supported may include one or moreof the JPEG standards, the MPEG standards, and the H.26x standards. Inone or more embodiments of the invention, the ICP (1202) is configuredto perform the computational operations of an embodiment of thecompression and decompression methods described herein.

In operation, to capture an image or video sequence, video signals arereceived by the video FE (1208) and converted to the input format neededto perform video encoding. The video data generated by the video FE(1208) is stored in then stored in external memory. Prior to storing thevideo data in external memory, the video data is compressed using amethod for compression described herein. The video data is then encodedby a video encoder. During the encoding process, the video encoder readsthe compressed input video data from the external memory and thecomputations for encoding this video data are performed by the ICP(1202). The reference pictures generated during video encoding arecompressed using a method for compression described herein. As thecompressed reference picture video data is read from the externalmemory, the reference picture video data is decompressed using a methodfor decompression described herein. The encoded video data may then beread from the external memory, decoded, and post-processed by the videoBE (1210) to display the image/video sequence.

FIG. 13 is a block diagram of a digital system (e.g., a mobile cellulartelephone) (1300) that may be configured to perform the methodsdescribed herein. The signal processing unit (SPU) (1302) includes adigital processing processor system (DSP) that includes embedded memoryand security features. The analog baseband unit (1304) receives a voicedata stream from handset microphone (1313 a) and sends a voice datastream to the handset mono speaker (1313 b). The analog baseband unit(1304) also receives a voice data stream from the microphone (1314 a)and sends a voice data stream to the mono headset (1314 b). The analogbaseband unit (1304) and the SPU (1302) may be separate ICs. In manyembodiments, the analog baseband unit (1304) does not embed aprogrammable processor core, but performs processing based onconfiguration of audio paths, filters, gains, etc being setup bysoftware running on the SPU (1302). In some embodiments, the analogbaseband processing is performed on the same processor and can sendinformation to it for interaction with a user of the digital system(1300) during a call processing or other processing.

The display (1320) may also display pictures and video streams receivedfrom the network, from a local camera (1328), or from other sources suchas the USB (1326) or the memory (1312). The SPU (1302) may also send avideo stream to the display (1320) that is received from various sourcessuch as the cellular network via the RF transceiver (1306) or the camera(1326). The SPU (1302) may also send a video stream to an external videodisplay unit via the encoder (1322) over a composite output terminal(1324). The encoder unit (1322) may provide encoding according toPAL/SECAM/NTSC video standards.

The SPU (1302) includes functionality to perform the computationaloperations required for video encoding and decoding. The video encodingstandards supported may include, for example, one or more of the JPEGstandards, the MPEG standards, and the H.26x standards. In one or moreembodiments of the invention, the SPU (1302) is configured to performthe computational operations of one or more of the methods forcompression and decompression of digital image data described herein.Software instructions implementing the one or more methods may be storedin the memory (1312) and executed by the SPU (1302) as part of capturingand/or encoding of digital image data, e.g., pictures and video streams.

FIG. 14 shows a digital system (1400) (e.g., a personal computer) thatincludes a processor (1402), associated memory (1404), a storage device(1406), and numerous other elements and functionalities typical ofdigital systems (not shown). In one or more embodiments of theinvention, a digital system may include multiple processors and/or oneor more of the processors may be digital signal processors. The digitalsystem (1400) may also include input means, such as a keyboard (1408)and a mouse (1410) (or other cursor control device), and output means,such as a monitor (1412) (or other display device). The digital system(1400) may also include an image capture device (not shown) thatincludes circuitry (e.g., optics, a sensor, readout electronics) forcapturing video sequences. The digital system (1400) may include a videoencoder with functionality to perform embodiments of the methods asdescribed herein. The digital system (1400) may be connected to anetwork (1414) (e.g., a local area network (LAN), a wide area network(WAN) such as the Internet, a cellular network, any other similar typeof network and/or any combination thereof) via a network interfaceconnection (not shown). Those skilled in the art will appreciate thatthe input and output means may take other forms.

Further, those skilled in the art will appreciate that one or moreelements of the aforementioned digital system (1400) may be located at aremote location and connected to the other elements over a network.Further, embodiments of the invention may be implemented on adistributed system having a plurality of nodes, where each portion ofthe system and software instructions may be located on a different nodewithin the distributed system. In one embodiment of the invention, thenode may be a digital system. Alternatively, the node may be a processorwith associated physical memory. The node may alternatively be aprocessor with shared memory and/or resources.

Software instructions to perform embodiments of the invention may bestored on a computer readable medium such as a compact disc (CD), adiskette, a tape, a file, memory, or any other computer readable storagedevice. The software instructions may be distributed to the digitalsystem (1400) via removable computer readable media (e.g., floppy disk,optical disk, flash memory, USB key), via a transmission path fromcomputer readable media on another digital system, etc.

While the invention has been described with respect to a limited numberof embodiments, those skilled in the art, having benefit of thisdisclosure, will appreciate that other embodiments can be devised whichdo not depart from the scope of the invention as disclosed herein. Forexample, the compression and decompression may be applied to a segmentof consecutive pixels that is shorter than a line. In another example, aspecial encoding mode may be added to further improve the compressionperformance by preventing expansion. Expansion occurs when the number ofbits used to encode a line of pixels is larger than the number of bitsin the unencoded line. In this special mode, the number of bits neededto encode a line of pixels is counted prior to actually encoding thepixels. If the number of bits exceeds the number of bits in the originalline of pixels, then the original pixel values in the line are outputinstead of encoding them. In another example, rather than using theabove cited neighbors for a pixel for spatial prediction and determininguse of run mode encoding/decoding, only the left neighbor may be used.In another example, in the two-pass approach for selecting an entropycode, rather than counting bits for every pixel, the bits may be countedevery N pixels. Accordingly, the scope of the invention should belimited only by the attached claims.

It is therefore contemplated that the appended claims will cover anysuch modifications of the embodiments as fall within the true scope andspirit of the invention.

What is claimed is:
 1. A method of compressing digital image datacomprising: selecting an entropy code for encoding a line of pixels inthe digital image data, wherein the entropy code is selected from aplurality of variable length entropy codes; using spatial prediction tocompute a pixel predictor and a pixel residual for a pixel in the lineof pixels, wherein using spatial prediction comprises computing aminimum absolute sample difference (MASD) for the pixel based onneighboring pixels, wherein the neighboring pixels are a leftneighboring pixel in the line of pixels, a top left neighboring pixel ina previous line of pixels, and a top neighboring pixel in the previousline of pixels, and wherein computing the MASD comprises computing anabsolute sample difference (ASD) between the top left neighboring pixeland the top neighboring pixel, an ASD between the top left neighboringpixel and the left neighboring pixel, and an ASD between the top leftneighboring pixel and an interpolated pixel value computed from the topneighboring pixel and the left neighboring pixel; and computing thepixel predictor and the pixel residual based on the MASD; andselectively encoding the pixel residual using one of the entropy code orrun mode encoding.
 2. The method of claim 1, wherein selecting anentropy code comprises: counting a number of bits required for encodingthe line of pixels using each of the variable length entropy codes; andselecting a variable length entropy code that requires a least number ofbits as the entropy code.
 3. The method of claim 1, wherein selecting anentropy code comprises: counting a number of bits required for encodinga previous line of pixels using each of the variable length entropycodes as the previous line is encoded; and selecting a variable lengthentropy code that requires a least number of bits as the entropy codefor the line of pixels.
 4. The method of claim 3, wherein the pluralityof variable length codes comprises a Golomb code of order 1, a Golombcode of order 2, an exp-Golomb code of order 0, and an exp-Golomb codeof order
 1. 5. The method of claim 1, wherein selectively encodingcomprises: using run mode encoding to encode the pixel residual when apixel residual of a previous pixel in the line of pixels is zero andselected neighboring pixels of the pixel have a same value; and usingthe entropy code to encode the pixel residual when the pixel residual ofthe previous pixel in the line of pixels is not zero or the selectedneighboring pixels do not have the same value.
 6. The method of claim 5,wherein the selected neighboring pixels are the previous pixel, a topleft neighboring pixel in a previous line of pixels, a top neighboringpixel in the previous line of pixels, and a top right neighboring pixelin the previous line of pixels.
 7. The method of claim 5, wherein usingrun mode encoding comprises: when the pixel residual is zero and iscomprised in a consecutive sequence of zero value pixel residuals,encoding the pixel residual in a code word representing the consecutivesequence, wherein the code word comprises a unary prefix of N zero valuebits representing N consecutive subsets of the consecutive sequence, abinary suffix of length log₂(N+1) bits, and a single one value bitbetween the unary prefix and the binary suffix, wherein for each bitposition n=1 to N in the unary prefix, a zero value bit in a bitposition n encodes an nth subset of length 2^(n) of the N consecutivesubsets, and wherein the binary suffix is a binary number indicating anumber M of zero value pixel residuals in an (N+1)th consecutive subsetof the consecutive sequence of zero value pixel residuals, whereinM<N+1.
 8. The method of claim 5, wherein using run mode encodingcomprises: incrementing a count of a number of consecutive zero valuepixel residuals when the pixel residual is zero; outputting a zero valuebit when the count is equal to a current code length and doubling thecurrent code length; and outputting a one bit followed by a binarynumber of length log₂(current code length) and setting the current codelength to two when the pixel residual is not zero, wherein the binarynumber is the count.
 9. A method of compressing digital image datacomprising: computing a minimum absolute sample difference (MASD) for apixel in a line of pixels based on neighboring pixels, wherein theneighboring pixels are a left neighboring pixel in the line of pixels, atop left neighboring pixel in a previous line of pixels, and a topneighboring pixel in the previous line of pixels, and wherein computingthe MASD comprises computing an absolute sample difference (ASD) betweenthe top left neighboring pixel and the top neighboring pixel, an ASDbetween the top left neighboring pixel and the left neighboring pixel,and an ASD between the top left neighboring pixel and an interpolatedpixel value computed from the top neighboring pixel and the leftneighboring pixel; computing a pixel predictor and a pixel residual forthe pixel based on the MASD; and selectively encoding the pixel residualusing one of an entropy code or run mode encoding.
 10. The method ofclaim 9, wherein selectively encoding comprises: using run mode encodingto encode the pixel residual when a pixel residual of the leftneighboring pixel is zero and the left neighboring pixel, the top leftneighboring pixel, the top neighboring pixel, and a top rightneighboring pixel in the previous line of pixels have a same value; andusing the entropy code to encode the pixel residual when the pixelresidual of the left neighboring pixel is not zero or the leftneighboring pixel, the top left neighboring pixel, the top neighboringpixel, and the top right neighboring pixel do not have a same value. 11.The method of claim 9, further comprising: counting a number of bitsrequired for encoding the line of pixels using each of a plurality ofvariable length entropy codes; and selecting a variable length entropycode that requires a least number of bits as the entropy code.
 12. Themethod of claim 9, further comprising: counting a number of bitsrequired for encoding a previous line of pixels using each of aplurality of variable length entropy codes as the previous line isencoded; and selecting a variable length entropy code that requires aleast number of bits as the entropy code.
 13. The method of claim 10,wherein using run mode encoding to encode the pixel residual comprises:when the pixel residual is zero and is comprised in a consecutivesequence of zero value pixel residuals, encoding the pixel residual in acode word representing the consecutive sequence, wherein the code wordcomprises a unary prefix of N zero value bits representing N consecutivesubsets of the consecutive sequence, a binary suffix of length log₂(N+1)bits, and a single one value bit between the unary prefix and the binarysuffix, wherein for each bit position n=1 to N in the unary prefix, azero value bit in a bit position n encodes an nth subset of length 2^(n)of the N consecutive subsets, and wherein the binary suffix is a binarynumber indicating a number M of zero value pixel residuals in an (N+1)thconsecutive subset of the consecutive sequence of zero value pixelresiduals, wherein M<N+1.
 14. The method of claim 10, wherein using runmode encoding to encode the pixel residual comprises: incrementing acount of a number of consecutive zero value pixel residuals when thepixel residual is zero; outputting a zero value bit when the count isequal to a current code length and doubling the current code length; andoutputting a one bit followed by a binary number of length log₂(currentcode length) and setting the current code length to two when the pixelresidual is not zero, wherein the binary number is the count.
 15. Amethod of compressing digital image data comprising: using spatialprediction to compute a pixel predictor and a pixel residual for a pixelin a line of pixels, wherein using spatial prediction comprisescomputing a minimum absolute sample difference (MASD) for the pixelbased on neighboring pixels, wherein the neighboring pixels are a leftneighboring pixel in the line of pixels, a top left neighboring pixel ina previous line of pixels, and a top neighboring pixel in the previousline of pixels, and wherein computing the MASD comprises computing anabsolute sample difference (ASD) between the top left neighboring pixeland the top neighboring pixel, an ASD between the top left neighboringpixel and the left neighboring pixel, and an ASD between the top leftneighboring pixel and an interpolated pixel value computed from the topneighboring pixel and the left neighboring pixel; and computing thepixel predictor and the pixel residual based on the MASD; encoding thepixel residual using run mode encoding when a pixel residual of aprevious pixel in the line of pixels is zero and selected neighboringpixels of the pixel have a same value; and encoding the pixel residualusing an entropy code when the pixel residual of the previous pixel inthe line of pixels is not zero or the selected neighboring pixels of thepixel do not have the same value.
 16. The method of claim 15, whereinthe selected neighboring pixels are the previous pixel, a top leftneighboring pixel in a previous line of pixels, a top neighboring pixelin the previous line of pixels, and a top right neighboring pixel in theprevious line of pixels.
 17. The method of claim 15, wherein encodingthe pixel residual using run mode encoding comprises: when the pixelresidual is zero and is comprised in a consecutive sequence of zerovalue pixel residuals, encoding the pixel residual in a code wordrepresenting the consecutive sequence, wherein the code word comprises aunary prefix of N zero value bits representing N consecutive subsets ofthe consecutive sequence, a binary suffix of length log₂(N+1) bits, anda single one value bit between the unary prefix and the binary suffix,wherein for each bit position n=1 to N in the unary prefix, a zero valuebit in a bit position n encodes an nth subset of length 2^(n) of the Nconsecutive subsets, and wherein the binary suffix is a binary numberindicating a number M of zero value pixel residuals in an (N+1)thconsecutive subset of the consecutive sequence of zero value pixelresiduals, wherein M<N+1.
 18. The method of claim 15, wherein encodingthe pixel residual using run mode encoding comprises: incrementing acount of a number of consecutive zero value pixel residuals when thepixel residual is zero; outputting a zero value bit when the count isequal to a current code length and doubling the current code length; andoutputting a one bit followed by a binary number of length log₂(currentcode length) and setting the current code length to two when the pixelresidual is not zero, wherein the binary number is the count.
 19. Themethod of claim 15, wherein the entropy code is selected from aplurality of variable length entropy codes by one selected from a groupconsisting of: counting a number of bits required for encoding the lineof pixels using each of the variable length entropy codes and selectinga variable length entropy code that requires a least number of bits asthe entropy code, and counting a number of bits required for encoding aprevious line of pixels using each of the variable length entropy codesas the previous line is encoded and selecting a variable length entropycode that requires a least number of bits as the entropy code.